import React from "react";
import {inject, observer} from 'mobx-react';
const {WeaTools} = getEcCom();
import { getAntd,getEcCom,getComsMobx,getLabel } from '../../../util/convert';
import * as type from "../../../constants/type";
@inject('globalStore','freeWorkflowNewStore','EnableProcessAdditionAndSubtractionStore')
@observer
export default class EnableProcessAdditionAndSubtractionComponents extends React.Component {
    constructor(props) {
        super(props);
    }
    componentDidMount() {//一些初始化请求
        const { clicknodeid,clickrequestid,signType } = this.props.freeWorkflowNewStore;
        const { getDetailInfo,setNodeid,setRequestid,RadioChange } = this.props.EnableProcessAdditionAndSubtractionStore;
             setNodeid(clicknodeid);
             setRequestid(clickrequestid);

             getDetailInfo();
    }
    componentWillReceiveProps(nextProps) {
    }
    componentWillUnmount() {
        //组件卸载时一般清理一些状态
    }
    showInfo=()=>{
        const { EnableProcessAdditionAndSubtractionStore } = this.props;
        const { initialDatas_wait } = EnableProcessAdditionAndSubtractionStore;
    }
    render() {
        const { WeaDialogFooter,WeaRightMenu } = getEcCom();
        return (
            <div className="wea-form-item-group" >
                <div style={{height:"350px",overflow:"auto",padding:'20px 30px 10px 30px'}} >
                    <WeaRightMenu {...this.getMoreBtns()}>
                        {this.getConditions()}
                    </WeaRightMenu>
                </div>
                <WeaDialogFooter buttons={this.getButtons()} moreBtn={this.getMoreBtns()} />
            </div>
        );
    }
    getConditions(){
        const { WeaBrowser, WeaFormItem, WeaSearchGroup,WeaSelect } = getEcCom();
        const { Radio,Row,Col,Input } = getAntd();
        const { RadioGroup }  = Radio.Group;
        const { nodeid="",nodeidspan="",userid="",useridspan="",setUpdatePerson,RadioChange } = this.props.EnableProcessAdditionAndSubtractionStore;
        const { signType,setProperty } = this.props.freeWorkflowNewStore;
        RadioChange(signType);
        setUpdatePerson(userid);
        let userid_arr = userid.split(",")||[];
        let useridspan_arr = useridspan.split(",")||[];
        let replace_data = [];
        for(let x=0;x<userid_arr.length;x++){
            replace_data.push({id:userid_arr[x],name:useridspan_arr[x]});
        }
        let group = [];
        let items = [];
        items.push({
            com:(<WeaFormItem
                label={getLabel(529896,'操作节点')}
                labelCol={{span:6}}
                wrapperCol={{span:18}}
                style={{"text-align":"center"}}
            >
                <Row >
                    <Col span={24} style={{"text-align":'left'}}>
                        <Input
                            style={{ width: "80%" }}
                            value =  {nodeidspan}
                            disabled = {true}
                        >
                        </Input>
                    </Col>
                </Row>
            </WeaFormItem>),
            colSpan:1
        })
        items.push({
            com:(   <WeaFormItem
                label={getLabel(529897,'操作人员')}
                labelCol={{span: 6}}
                wrapperCol={{span: 18}}
                style={{"text-align":"center"}}
            >
                <WeaBrowser
                    fieldName='userid'
                    type={17}
                    isSingle={false}
                    title={getLabel(529897,'操作人员')}
                    addOnClick={values =>alert(values)}
                    inputStyle={{ width: "80%" }}
                    replaceDatas={replace_data}
                    viewAttr={3}
                    onChange={(ids, names, datas) =>{
                        setUpdatePerson(ids);
                        setProperty({selectedPersons:{ids, names, datas}});
                    }
                    }
                />
            </WeaFormItem>),
            colSpan:1
        })
        const options = [
            {
                key: "2",
                selected: true,
                showname: "依次逐个处理"
            },{
                key: "1",
                selected: false,
                showname: "会签"
            }
        ];
        items.push({
            com:(<WeaFormItem
                label={getLabel(529939,'会签属性')}
                labelCol={{span: 6}}
                wrapperCol={{span: 18}}
                style={{"text-align":"center"}}
            >
                <Row >
                    <Col span={24} style={{"text-align":'left'}}>
                        <WeaSelect
                            options={options}
                            value={signType}
                            detailtype={3}
                            supportCancel
                            onChange={(v,showname)=>{
                                RadioChange(v)
                            }}
                        />
                    </Col>
                </Row>
            </WeaFormItem>),
            colSpan:1
        })
        group.push(<WeaSearchGroup needTigger={false} showGroup={true} items={items} col={1}/>)
        return <div>{group}</div>;
    }
    getButtons(){
        const { Button } = getAntd();
        let buttons = [];
        buttons.push(<Button type='primary' onClick={()=>{
            this.doSubmit();
        }}>{getLabel(83446,'确定')}</Button>);
        buttons.push(<Button type='primary' onClick={()=>{
            this.doCancel();
        }}>{getLabel(201,'取消')}</Button>);
        return buttons;
    }
    doSubmit(){
        const { clicknodeid } = this.props.freeWorkflowNewStore;
        const { saveUpdateInfo,signType,addNextNode } = this.props.EnableProcessAdditionAndSubtractionStore;
        if(signType=="2"){//如果是依次逐个处理
            addNextNode({addnodeid:clicknodeid});
        }else{
            saveUpdateInfo();
        }

    }
    doCancel(){
        const { controlDialogVisible } = this.props.globalStore;
        controlDialogVisible(type.EnableProcessAdditionAndSubtraction,false);
    }
    getMoreBtns(){
        let btns = [];
        btns.push({
            key: '0',
            icon:  <i className='icon-coms-Preservation'/>,
            content: getLabel(83446,'确定'),
            onClick: key => this.doConfirm(),
        });
        btns.push({
            key: '1',
            icon:  <i className='icon-coms-Preservation'/>,
            content: getLabel(201,'取消'),
            onClick: key => this.doConfirm(),
        });
        return {datas:btns};
    }

}
//组件检错机制
class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg = this.props.error && this.props.error !== "";
        return(
            <WeaErrorPage msg={ hasErrorMsg ? this.props.error : getLabel(384697, "对不起，该页面异常，请联系管理员！") } />
        );
    }
}
EnableProcessAdditionAndSubtractionComponents = WeaTools.tryCatch( React, MyErrorHandler, { error: "" })(EnableProcessAdditionAndSubtractionComponents);
